import request from '@/utils/request'

const api = "/admin/pro"    // 商品接口

export interface ProductType {
    id: number,
    name: string,
    imageUrl: string,
    price: number,
    sales: number,
    comments: number,
    isAd: boolean,   // 是否广告 
    inventory: number,  // 库存
    status: number,     // 状态 1上架 0下架
    tags: string,   // 标签
}

export default {
  // 分页获取商品列表
  getProductList(pageNo: number, pageSize: number, sortBy: string, isAsc: boolean) {
    return request({
      url: `${api}/list`,
      method: 'get',
      params: { pageNo, pageSize, sortBy, isAsc }
    })
  },
  // 获取商品详情
  getProductDetail(id: number) {
    return request({
      url: `${api}/detail`,
      method: 'get',
      params: { id }
    })
  },
  // 添加商品
  addProduct(data: ProductType) {
    return request({
      url: `${api}/add`,
      method: 'post',
      data
    })
  },
  // 修改商品
  updateProduct(data: ProductType) {
    return request({
      url: `${api}/update`,
      method: 'post',
      data
    })
  },
  // 分页条件搜索商品
  searchProduct(pageNo: number, pageSize: number, sortBy: string, isAsc: boolean, name: string, minPrice: number, maxPrice: number) {
    const data = {
      pageNo,
      pageSize,
      sortBy,
      isAsc,
      name,
      minPrice,
      maxPrice
    }
    return request({
      url: `${api}/search`,
      method: 'post',
      data
    })
  },
}